<?php
/**
 * 商品分类服务层
 * @author maniac
 */
namespace app\common\service;

use app\common\model\GoodCategory AS GoodCategoryModel;

class GoodCategory extends Base
{
    /**
     * 获取所有终极栏目
     * @param  string $ids id
     */
    public function getLastCategories($ids)
    {
        $where = [
            ['id', 'in', $ids],
            ['is_last', 'eq', 1],
        ];
        return GoodCategoryModel::where($where)->column('id');
    }
    
    /**
     * 获取商品分类
     * @param string $where 查询条件
     * @param string $limit 分页条件
     * @param string $order 排序条件
     */
    public function categories($where = '', $limit = '', $order = 'list_order DESC,id ASC')
    {

        $append=['image_uri', 'ad_uri','parent_name'];
        if(is_array($where)){
            if(isset($where["get_goods"])){
                $append[]="goods_list";
                unset($where["get_goods"]);
            }
        }


        return GoodCategoryModel::field('id,parent_id,good_mods_id,name,alias_name,is_last,image_id,ad_id')
            ->append($append)
            ->where($where)
            ->order($order)->limit($limit)->select()->toArray();
    }
}
